package com.hunter.test;

import com.hunter.hmi.Hmi;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @Project:iwms
 * @Description: test
 * @Author: Mr.Hunter
 * @Date:2022/6/7/9:12
 */
public class MousePointerListenter {
    private JTextField xtextField;
    private JTextField ytextField;

    public void dome(){
        JFrame jf = new JFrame();
        jf.setLayout(new FlowLayout());
        jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setUndecorated(true);
        jf.setBackground(new Color(0,0,150,150));
        jf.setVisible(true);
        jf.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == e.BUTTON1){

                    PointerInfo pinfo = MouseInfo.getPointerInfo();
                    int mx = pinfo.getLocation().x;
                    int my = pinfo.getLocation().y;
                    xtextField.setText(""+mx);
                    ytextField.setText(""+my);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ee) {
                        System.out.println(ee.getMessage());
                    }

                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getButton() == e.BUTTON3){

                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
    }


}